<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="项目名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- 
      <el-form-item label="项目简介" prop="introduction">
        <el-input
          v-model="queryParams.introduction"
          placeholder="请输入项目简介"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="成立时间" prop="establishTime">
        <el-input
          v-model="queryParams.establishTime"
          placeholder="请输入成立时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="所在地" prop="location">
        <el-input
          v-model="queryParams.location"
          placeholder="请输入所在地"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="发币情况" prop="coinIssuanceSatus">
        <el-input
          v-model="queryParams.coinIssuanceSatus"
          placeholder="请输入发币情况"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="代币缩写" prop="tokenAbbreviation">
        <el-input
          v-model="queryParams.tokenAbbreviation"
          placeholder="请输入代币缩写"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公募价格" prop="publicOfferingPrice">
        <el-input
          v-model="queryParams.publicOfferingPrice"
          placeholder="请输入公募价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上传审计报告pdf" prop="auditReportUrl">
        <el-input
          v-model="queryParams.auditReportUrl"
          placeholder="请输入上传审计报告pdf"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['projectInclusion:projectInclusion:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['projectInclusion:projectInclusion:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['projectInclusion:projectInclusion:remove']"
          >删除</el-button
        >
      </el-col>
    
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row> -->

    <el-table
      v-loading="loading"
      :data="projectInclusionList"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <!-- <el-table-column label="主表id" align="center" prop="mainId" /> -->
      <!-- <el-table-column label="logo" align="center" prop="logoUrl" /> -->
      <el-table-column label="项目名称" align="center" prop="name" />
      <el-table-column label="项目官网" align="center" prop="officialWebsite" />
      <el-table-column label="项目简介" align="center" prop="introduction" />
      <!-- <el-table-column label="项目介绍" align="center" prop="content" /> -->
      <!-- <el-table-column label="标签" align="center" prop="label" />
      <el-table-column label="生态" align="center" prop="ecology" /> -->
      <el-table-column label="成立时间" align="center" prop="establishTime" />
      <el-table-column label="所在地" align="center" prop="location" />
      <!-- <el-table-column
        label="白皮书连接"
        align="center"
        prop="whitePaperLink"
      /> -->
      <!-- <el-table-column
        label="白皮书上传pdf"
        align="center"
        prop="whitePaperUrl"
      /> -->
      <el-table-column
        label="发币情况"
        align="center"
        prop="coinIssuanceSatus"
        :formatter="groupFormate"
      />
      <!-- <el-table-column
        label="代币缩写"
        align="center"
        prop="tokenAbbreviation"
      />
      <el-table-column
        label="公募价格"
        align="center"
        prop="publicOfferingPrice"
      /> -->
      <el-table-column
        label="运营状态"
        align="center"
        prop="operateStatus"
        :formatter="groupOperateStatusFormate"
      />
      <el-table-column label="审核状态" align="center" prop="exStatus" />

      <!-- <el-table-column
        label="有无审计报告"
        align="center"
        prop="auditReportStatus"
      />
      <el-table-column
        label="上传审计报告pdf"
        align="center"
        prop="auditReportUrl"
      />
      <el-table-column label="团队成员" align="center" prop="teamMember" />
      <el-table-column label="类型" align="center" prop="tokenType" /> -->
      <!-- <el-table-column label="语言类型" align="center" prop="lang" /> -->
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <!-- <el-table-column label="修改前id" align="center" prop="oldId" />
      <el-table-column label="修改前语言" align="center" prop="oldLang" /> -->
      <!-- <el-table-column
        label="其他审计事务所"
        align="center"
        prop="auditFirms"
      /> -->
      <!-- <el-table-column label="公司名称" align="center" prop="companyName" />
      <el-table-column label="审计时间" align="center" prop="auditTime" /> -->
      <!-- <el-table-column label="公司logo" align="center" prop="companyLogo" /> -->
      <!-- <el-table-column label="ipfshash" align="center" prop="qmHash" /> -->
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['projectInclusion:projectInclusion:edit']"
            >查看</el-button
          >
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['projectInclusion:projectInclusion:remove']"
            >删除</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目收录对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1200px"
      append-to-body
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        :disabled="true"
        label-width="100px"
      >
        <!-- <el-form-item label="主键id" prop="id">
          <el-input v-model="form.id" placeholder="请输入主键id" />
        </el-form-item>
        <el-form-item label="主表id" prop="mainId">
          <el-input v-model="form.mainId" placeholder="请输入主表id" />
        </el-form-item> -->
        <el-form-item label="logo" prop="logoUrl">
          <el-image
            style="width: 100px; height: 100px"
            :src="imageUrl + form.logoUrl"
            fit="cover"
          ></el-image>
        </el-form-item>
        <el-form-item label="项目名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="项目官网" prop="officialWebsite">
          <el-input v-model="form.officialWebsite" type="textarea" />
        </el-form-item>
        <el-form-item label="项目简介" prop="introduction">
          <el-input v-model="form.introduction" placeholder="请输入项目简介" />
        </el-form-item>
        <el-form-item label="项目介绍">
          <el-input :rows="10" v-model="form.content" type="textarea" />
        </el-form-item>
        <el-form-item label="标签" prop="label">
          <el-input v-model="form.label" type="textarea" />
        </el-form-item>
        <el-form-item label="生态" prop="ecology">
          <el-input v-model="form.ecology" type="textarea" />
        </el-form-item>
        <el-form-item label="成立时间" prop="establishTime">
          <el-input v-model="form.establishTime" placeholder="请输入成立时间" />
        </el-form-item>
        <el-form-item label="所在地" prop="location">
          <el-input v-model="form.location" placeholder="请输入所在地" />
        </el-form-item>
        <el-form-item label="白皮书连接" prop="whitePaperLink">
          <el-input v-model="form.whitePaperLink" type="textarea" />
        </el-form-item>
        <el-form-item
          label="白皮书pdf"
          prop="whitePaperUrl"
          v-if="this.form.whitePaperUrl != '' ? true : false"
        >
          <file-upload v-model="form.whitePaperUrl" />
        </el-form-item>
        <el-form-item label="发币情况" prop="coinIssuanceSatus">
          <el-input
            v-model="this.coinIssuanceSatus"
            placeholder="请输入发币情况"
          />
        </el-form-item>
        <el-form-item
          label="代币缩写"
          prop="tokenAbbreviation"
          v-if="this.form.tokenAbbreviation != '' ? true : false"
        >
          <el-input
            v-model="form.tokenAbbreviation"
            placeholder="请输入代币缩写"
          />
        </el-form-item>
        <el-form-item
          label="公募价格"
          prop="publicOfferingPrice"
          v-if="this.form.publicOfferingPrice != '' ? true : false"
        >
          <el-input
            v-model="form.publicOfferingPrice"
            placeholder="请输入公募价格"
          />
        </el-form-item>
        <el-form-item
          label="审计报告pdf"
          prop="auditReportUrl"
          v-if="this.form.auditReportUrl != '' ? true : false"
        >
          <file-upload v-model="form.auditReportUrl" />
        </el-form-item>
        <!-- <el-form-item label="团队成员" prop="teamMember">
          <el-input
            v-model="form.teamMember"
            type="textarea"
           
          />
        </el-form-item> -->
        <!-- <el-form-item label="语言类型" prop="lang">
          <el-input v-model="form.lang" placeholder="请输入语言类型" />
        </el-form-item> -->
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" />
        </el-form-item>
        <!-- <el-form-item label="修改前id" prop="oldId">
          <el-input v-model="form.oldId" placeholder="请输入修改前id" />
        </el-form-item>
        <el-form-item label="修改前语言" prop="oldLang">
          <el-input v-model="form.oldLang" placeholder="请输入修改前语言" />
        </el-form-item> -->
        <!-- <el-form-item
          label="审计事务所"
          prop="auditFirms"
          v-if="this.form.auditFirms != '' ? true : false"
        >
          <el-input
            v-model="form.auditFirms"
            placeholder="请输入其他审计事务所"
          />
        </el-form-item> -->
        <!-- <el-form-item label="公司名称" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入公司名称" />
        </el-form-item> -->
        <el-form-item label="审计时间" prop="auditTime">
          <el-input v-model="form.auditTime" placeholder="请输入审计时间" />
        </el-form-item>
        <!-- <el-form-item label="公司logo" prop="companyLogo">
          <el-image
            style="width: 100px; height: 100px"
            :src="imageUrl + form.companyLogo"
            fit="cover"
          ></el-image>
        </el-form-item> -->
        <!-- <el-form-item label="ipfshash" prop="qmHash">
          <el-input v-model="form.qmHash" placeholder="请输入ipfshash" />
        </el-form-item> -->
        <el-form-item label="团队成员" prop="workExperienceList">
          <el-table :data="form.workExperienceList" style="width: 100%">
            <el-table-column prop="name" label="名称" width="180">
            </el-table-column>
            <el-table-column prop="post" label="岗位" width="180">
            </el-table-column>
            <el-table-column prop="time" label="工作时间"> </el-table-column>
          </el-table>
        </el-form-item>
        <el-form-item label="社媒链接" prop="smcList">
          <el-table :data="form.smcList" style="width: 100%">
            <el-table-column prop="webType" label="名称" width="180">
            </el-table-column>
            <el-table-column prop="webUrl" label="链接"> </el-table-column>
          </el-table>
        </el-form-item>

        <el-form-item label="关键事件" prop="eventList">
          <el-table :data="form.eventList" style="width: 100%">
            <el-table-column prop="event" label="名称" width="180">
            </el-table-column>
            <el-table-column prop="createTime" label="时间" width="180">
            </el-table-column>
            <el-table-column prop="link" label="链接"> </el-table-column>
          </el-table>
        </el-form-item>

        <el-form-item label="投资详情" prop="projectInvestDetailsList">
          <el-table :data="form.projectInvestDetailsList" style="width: 100%">
            <el-table-column prop="round" label="轮次" width="50">
            </el-table-column>
            <el-table-column prop="amount" label="金额" width="100">
            </el-table-column>
            <el-table-column prop="valuation" label="估值"> </el-table-column>
            <el-table-column prop="time" label="时间"> </el-table-column>
            <el-table-column prop="led" label="领投" :formatter="ledsFormate">
            </el-table-column>
            <el-table-column prop="investor" label="投资方"> </el-table-column>
            <el-table-column prop="link" label="链接"> </el-table-column>
          </el-table>
        </el-form-item>
        <el-form-item label="对外投资" prop="foreignInvestList">
          <el-table :data="form.foreignInvestList" style="width: 100%">
            <el-table-column prop="projectName" label="项目名" width="80">
            </el-table-column>
            <el-table-column prop="round" label="轮次" width="50">
            </el-table-column>
            <el-table-column prop="amount" label="金额" width="100">
            </el-table-column>
            <el-table-column prop="valuation" label="估值"> </el-table-column>
            <el-table-column prop="time" label="时间"> </el-table-column>
            <el-table-column
              prop="ledStatus"
              label="领投"
              :formatter="ledFormate"
            >
            </el-table-column>
            <!-- <el-table-column prop="investor" label="投资方"> </el-table-column> -->
            <el-table-column prop="link" label="链接"> </el-table-column>
          </el-table>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listProjectInclusion,
  getProjectInclusion,
  delProjectInclusion,
  addProjectInclusion,
  updateProjectInclusion,
  getExamineStatus,
} from "@/api/projectInclusion/projectInclusion";
import { imageUrl } from "@/config";

export default {
  name: "ProjectInclusion",
  data() {
    return {
      imageUrl,
      coinIssuanceSatus: null,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目收录表格数据
      projectInclusionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mainId: null,
        logoUrl: null,
        name: null,
        officialWebsite: null,
        introduction: null,
        content: null,
        label: null,
        ecology: null,
        establishTime: null,
        location: null,
        whitePaperLink: null,
        whitePaperUrl: null,
        coinIssuanceSatus: null,
        tokenAbbreviation: null,
        publicOfferingPrice: null,
        operateStatus: null,
        auditReportStatus: null,
        auditReportUrl: null,
        teamMember: null,
        tokenType: null,
        lang: null,
        oldId: null,
        oldLang: null,
        auditFirms: null,
        companyName: null,
        auditTime: null,
        companyLogo: null,
        qmHash: null,
        smcList: [],
        eventList: [],
      },
      status: "",
      // 表单参数
      form: {
        coinIssuanceSatus: null,
      },
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询项目收录列表 */
    getList() {
      this.loading = true;
      listProjectInclusion(this.queryParams).then((response) => {
        this.projectInclusionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    groupFormate(row) {
      if (row.lang == "0") {
        if (row.coinIssuanceSatus == 0) {
          return "IssuedCoins";
        } else {
          return "UnissuedCoins";
        }
      }
    },
    formatInput(value) {
      console.log("seweqeq", value);
      if (value == "0") {
        return "IssuedCoins";
      } else {
        return "UnissuedCoins";
      }
    },
    ledFormate(row) {
      if (row.ledStatus == "0") {
        return "no";
      } else if (row.ledStatus == "1") {
        return "yes";
      } else {
        return "-";
      }
    },
    ledsFormate(row) {
      if (row.led == "0") {
        return "no";
      } else if (row.led == "1") {
        return "yes";
      } else {
        return "-";
      }
    },
    Formatter(row, column) {
      getExamineStatus(row.id).then((response) => {
        this.status = response.msg;
      });
      return this.status;
    },

    groupOperateStatusFormate(row) {
      if (row.lang == "0") {
        if (row.operateStatus == 0) {
          return "Running";
        } else {
          return "Stopping Operations";
        }
      } else if (row.lang == "1") {
        if (row.operateStatus == 0) {
          return "正在运营";
        } else {
          return "停止运营";
        }
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        mainId: null,
        logoUrl: null,
        name: null,
        officialWebsite: null,
        introduction: null,
        content: null,
        label: null,
        ecology: null,
        establishTime: null,
        location: null,
        whitePaperLink: null,
        whitePaperUrl: null,
        coinIssuanceSatus: null,
        tokenAbbreviation: null,
        publicOfferingPrice: null,
        operateStatus: null,
        auditReportStatus: null,
        auditReportUrl: null,
        teamMember: null,
        tokenType: null,
        lang: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        oldId: null,
        oldLang: null,
        auditFirms: null,
        companyName: null,
        auditTime: null,
        companyLogo: null,
        qmHash: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加项目收录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getProjectInclusion(id).then((response) => {
        this.form = response.data;
        //格式化发币情况
        if ((this.form.coinIssuanceSatus = "0")) {
          this.coinIssuanceSatus = "IssuedCoins";
        } else if ((this.form.coinIssuanceSatus = "1")) {
          this.coinIssuanceSatus = "UnissuedCoins";
        } else if ((this.form.coinIssuanceSatus = "2")) {
          this.coinIssuanceSatus = "Empty";
        } else if ((this.form.coinIssuanceSatus = "3")) {
          this.coinIssuanceSatus = "NoTokens";
        }
        this.open = true;
        this.title = "查看项目收录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateProjectInclusion(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProjectInclusion(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除项目收录编号为"' + ids + '"的数据项？')
        .then(function () {
          return delProjectInclusion(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "projectInclusion/projectInclusion/export",
        {
          ...this.queryParams,
        },
        `projectInclusion_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
